
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @module index
* @author: Hjava
* @description: LoginSDK入口文件
* @since: 2018-07-17 18:55:46
*/
var authManager_1 = __webpack_require__(/*! _login/authManager */ "./src/core/login/authManager.ts");
var connection_1 = __webpack_require__(/*! _login/connection */ "./src/core/login/connection.ts");
var daemon_1 = __webpack_require__(/*! _login/daemon */ "./src/core/login/daemon.ts");
var timeCalibration_1 = __webpack_require__(/*! _login/timeCalibration */ "./src/core/login/timeCalibration.ts");
var analytics_1 = __webpack_require__(/*! _util/analytics */ "./src/core/utils/analytics.ts");
var constant = __webpack_require__(/*! _util/constant */ "./src/core/utils/constant.ts");
var constant_1 = __webpack_require__(/*! _util/constant */ "./src/core/utils/constant.ts");
var eventEmitter_1 = __webpack_require__(/*! _util/eventEmitter */ "./src/core/utils/eventEmitter.ts");
var packet_1 = __webpack_require__(/*! _util/packet */ "./src/core/utils/packet.ts");
var protocol_1 = __webpack_require__(/*! _util/protocol */ "./src/core/utils/protocol.ts");
var userData_1 = __webpack_require__(/*! _util/userData */ "./src/core/utils/userData.ts");
var LoginSDK = /** @class */ (function () {
    function LoginSDK(opts) {
        this.on = eventEmitter_1.default.on;
        this.once = eventEmitter_1.default.once;
        this.emit = eventEmitter_1.default.emit;
        this.off = eventEmitter_1.default.removeAllListeners;
        userData_1.default.setAll(opts);
        var appId = userData_1.default.get('appId');
        packet_1.default.prototype.appid = appId;
        var autoConnect = true;
        if (userData_1.default.get('autoConnect') !== void 0) {
            autoConnect = userData_1.default.get('autoConnect');
        }
        var shouldConnectWhenInit = true;
        // 只是用于设置在 Web Worker 中不初始化 WebSocket
        if ( true && userData_1.default.get('shouldConnectWhenInit') !== void 0) {
            shouldConnectWhenInit = userData_1.default.get('shouldConnectWhenInit');
        }
        this._connection = new connection_1.default({ autoConnect: autoConnect });
        this._authManager = new authManager_1.default(this._connection);
        this._timeCalibration = new timeCalibration_1.default(this._connection);
        this._daemon = new daemon_1.default(this._connection);
        this._connection.setDaemon(this._daemon);
        this._connection.connectWhenInit(shouldConnectWhenInit);
    }
    LoginSDK.prototype._sendTransUp = function (svid, request) {
        if (request) {
            request.setUid(this.getUID());
            var tran = new protocol_1.default.TransUp({
                __master: request.__master,
                'uri': constant_1.BASE_URI.URI_UNI_TRANSUP,
                'svid': svid,
                'uid': this.getUID(),
                'buf': request.getBytes()
            });
            this._send(tran);
        }
    };
    LoginSDK.prototype.getUID = function () {
        return userData_1.default.get('uid');
    };
    LoginSDK.prototype.getAppId = function () {
        return userData_1.default.get('appId');
    };
    LoginSDK.prototype.getConnectionUrl = function () {
        return this._connection.url;
    };
    LoginSDK.prototype.login = function (passport, password, supportMultiDevices, pushToken) {
        userData_1.default.set('_startLoginTime', Date.now());
        this._authManager.loginWithPassport(passport, password, supportMultiDevices, pushToken);
        userData_1.default.set('passport', passport);
        analytics_1.default.report('login_start');
    };
    LoginSDK.prototype.loginWithUidAndToken = function (uid, token, supportMultiDevices, pushToken) {
        userData_1.default.set('_startLoginTime', Date.now());
        this._authManager.loginWithUid(uid, token, supportMultiDevices, pushToken);
        userData_1.default.set('uid', uid);
        analytics_1.default.report('login_start');
    };
    LoginSDK.prototype.loginWithVisitor = function (uid, xsid) {
        userData_1.default.set('_startLoginTime', Date.now());
        this._authManager.loginWithVisitor(uid, xsid);
        analytics_1.default.report('login_start');
    };
    LoginSDK.prototype.logout = function () {
        this._authManager.logout();
        this.reconnect();
    };
    LoginSDK.prototype.logoutByFalseKickoff = function () {
        this._authManager.logoutByFalseKickoff();
    };
    LoginSDK.prototype.reconnect = function () {
        this._connection.reconnect();
    };
    LoginSDK.prototype._send = function (request) {
        this._connection.send(request);
    };
    LoginSDK.constant = constant;
    return LoginSDK;
}());
exports.default = LoginSDK;


//# sourceURL=webpack://MTDX/./src/core/login/index.ts?